/*代理，目的是让用户不能直接操作原对象*/
{
    let car = {
        name: 'bengchi',
        color: 'red',
        max_speed: '100/h'
    };

    let carProxy = new Proxy(car, {
        //用户通过carProxy对car进行操作时，对操作做一些修改
        get(from_car, key) {
            return from_car[key] + ' ,by carProxy';
        },
        set(from_car, key, changeValue) {
            if (key === 'name') {
                return 'you can`t change';
            } else {
                from_car[key] = changeValue;
                return 'ok by hhj';//返回一个自定义字符串
            }
        },
        //拦截处理'--' in obj操作
        has(from_car, key) {
            if (key === 'name') {
                return true;
            } else {
                return false;
            }
        },
        //拦截处理 delete obj.property操作
        deleteProperty(from_car, key){
            if (key==='name'){
                return 'fail';//返回自定义字符串
            }else {
                delete from_car[key];
                return 'success';//返回自定义字符串
            }
        },
        //拦截处理Object.keys()操作
        ownKeys(from_car){
           return Object.keys(from_car).filter(item=>item!='max_speed');//返回数组
        }
    });
    console.log(carProxy.color);
    carProxy.color = 'blue';
    console.log(carProxy.color);
    carProxy.name = 'hhj';
    console.log(carProxy.name);
    console.log('name' in carProxy,'max_speed' in carProxy);
    delete carProxy.name;
    delete carProxy.color;
    console.log(carProxy);
    console.log(Object.keys(carProxy));
}
